#include <iostream>
#include <vector>

using namespace std;

class Solution {
public:
    void moveZeroes(vector<int>& nums) {
        if (nums.size() < 2)
            return;

        int i = 0, j = 1;
        while (i < j) {
            while (i < nums.size() && nums[i] != 0)
                i++;

            j = i;
            while (j < nums.size() && nums[j] == 0)
                j++;

            // swap
            if (i < nums.size() && j < nums.size()) {
                int tmp = nums[i];
                nums[i] = nums[j];
                nums[j] = tmp;
            }
            else {
                break;
            }
            
        }
        
    }
};

void test01() {
    cout << "test01:" << endl;
    vector<int> input = {0,1,0,3,12};

    Solution obj;
    obj.moveZeroes(input);

    for (auto item : input) {
        cout << item << " ";
    }
    cout << endl;
}

void test02() {
    cout << "test02:" << endl;
    vector<int> input = {0};

    Solution obj;
    obj.moveZeroes(input);

    for (auto item : input) {
        cout << item << " ";
    }
    cout << endl;
}

void test03() {
    cout << "test03:" << endl;
    vector<int> input = {2, 0,1,0,3,0, 0, 0, 12};

    Solution obj;
    obj.moveZeroes(input);

    for (auto item : input) {
        cout << item << " ";
    }
    cout << endl;
}

// input [4,2,4,0,0,3,0,5,1,0]
// output:[4,2,4,3,5,1,0,0,0,0]
void test04() {
    cout << "test04:" << endl;
    vector<int> input = {4,2,4,0,0,3,0,5,1,0};

    Solution obj;
    obj.moveZeroes(input);

    for (auto item : input) {
        cout << item << " ";
    }
    cout << endl;
}


int main () {
    test01();
    test02();
    test03();
    test04();
    return 0;
}
